    export default {
        name: "login",
        setup(props) {
            const router = VueRouter.useRouter();
            const route = VueRouter.useRoute();
            const originalUser = ref({}); // 原始用户数据用于比较修改
            const token = ref(localStorage.getItem('token') || '');
            const formData = ref({username: '', password: ''});

            onMounted(async() => {
                const url = new URL(window.location.href);  // 解析来源网址
                if (url.origin == 'https://zp.kzhgzs.cn') {
                    formData.value = { username: 'admin', password: '123456' };
                }
                if (token.value) {
                    const res = await getuser(); //从token获取用户信息
                    originalUser.value = res;
                    localStorage.setItem('user', JSON.stringify(originalUser.value));
                    tohome();
                }
            });
            
            //登录
        	const submitUser = _.debounce(async() => {
                const res = await loginapi(formData.value);
                ElMessage.success("登录成功");
                token.value = res.token;
                localStorage.setItem('token', token.value);
                originalUser.value = await getuser();
                localStorage.setItem('user', JSON.stringify(originalUser.value));
                setTimeout(() => {
                    tohome();
                }, 100);
        	}, 1000);
        	
            const isadmin = computed(() => {
                return ['admin', 'xmgly'].includes(originalUser.value.Role);
            })
        	
        	const tohome = () => {
                // 处理重定向
                const redirect = decodeURIComponent(route.query.redirect || '');
                if(redirect) {
                    router.push(redirect);
                }else if(isadmin.value) {
        	        router.push({name: 'admin'});
        	    }else{
                    router.push({name: 'home'});
        	    }
        	}
        	
            return {
                isadmin,
                originalUser,
                token,
                submitUser,
                formData,
                loginapi,
                tohome,
            };
        },
        
        template: `
	<div class="header row">
		<div class="col-lg-2 col-md-0">&nbsp;</div>
		<div class="col-lg-10 col-md-12">
			<img class="icon-logo" src="/pc_static/logo.png" />
		</div>
	</div>

	<div class="c-center">
		<div style="height:7%;"></div>

		<div class="cen-form">
			<div class="ckhead">
				<p style="margin: 0; padding: 0;">用户登录</p>
			</div>
			<form class="form" method="post" @submit.prevent="submitUser">
				<div class="ckbd">
					<div class="ckleft">用户名：</div>
					<div class="ckright">
						<input id="username" class="cipnut" type="text" v-model="formData.username" placeholder="输入用户名"
							maxlength="50" required />
					</div>
				</div>
				<div class="ckbd mt30">
					<div class="ckleft">用户密码：</div>
					<div class="ckright">
						<input id="password" class="cipnut" type="password" v-model="formData.password"
							placeholder="输入密码" required />
					</div>
				</div>

				<div class="ckbd mt40 met20">
					<div class="ckleft"></div>
					<div class="ckright">
						<button class="inquire" type="submit">登录</button>
					</div>
				</div>
			</form>
			<div class="ckfoot">
				<div style="padding: 0 20px">
					温馨提示：请使用windows自带Edge浏览器，或谷歌、360等浏览器打开网页，不支持IE8及以下浏览器。
				</div>
			</div>
		</div>
		<div style="height:40px;"></div>
	</div>
        `
    }